# -*- coding: utf-8 -*-
"""
Created on Fri May  5 17:52:48 2023

@author: LJM
"""

import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', 50)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', None)
#dfjch = pd.read_excel('industry_classify.xlsx',sheet_name='Sheet2')
#%%
#获取映射字典
def get_dic(path='./data/industry_classify.xlsx'):
    classmap =  pd.read_excel(path,sheet_name='classmap',dtype=str).set_index('industry_code')#.class_code #不评价没有行业分类编码
    classmap.if_case = classmap.if_case.astype('float')
    codemap = pd.read_excel(path,sheet_name='codemap',dtype = str).set_index('industry_name').code  #不评价有code
    return codemap,classmap
# codemap,classmap = get_dic()

#%%
def to_classify(dfjch,codemap,classmap):
    dfjch.scale = dfjch.scale.map({'大':1,'中':1,'小':0,'微':0})
    dfjch['industry_code'] = dfjch.industry.map(codemap)
    dfjch['types'] = dfjch.industry_code.map(classmap.class_code)
    #是否区分大小
    dfjch['if_dis'] = dfjch.industry_code.map(classmap.if_case)
    dfjch.loc[dfjch.if_dis > 0,'scale'] = 2                        #不区分则填2
    dfjch['model_type'] = dfjch.types + dfjch.scale.astype('str')
    dfjch.model_type.fillna('bup',inplace=True)  #没有code或者没有行业分类编码会被定义成不评价
    return dfjch
